package com.jsj.controller;

import com.jsj.domain.Course;
import com.jsj.domain.StuClass;
import com.jsj.service.CourseService;
import com.jsj.service.StuClassService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/stuclass")
public class StuClassController {
    private StuClassService stuClassService;

    @Autowired
    public void setStuClassService(StuClassService stuClassService) {
        this.stuClassService = stuClassService;
    }

    /**
     * 创建课程
     */
    @RequestMapping(value = "/insert", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public AjaxResult insert(@RequestBody StuClass stuClass) {
        if (stuClassService.insert(stuClass) == 0) {
            return AjaxResult.error("创建课程失败");
        }
        return AjaxResult.success("创建课程成功");
    }
    /**
     * 根据
     */
    @RequestMapping(value = "/queryByName/{name}", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('student,teacher,admin')")
    public List<StuClass> queryByTitle(@PathVariable("name") String name) {
        startPage();
        return stuClassService.queryByName(name);
    }
}





